﻿using MovingChameLibrary.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace MovingChameLibrary.PersonalDataManager
{
    public class PersonalTourData
    {
        #region Static Variable
        private static PersonalTourData current;
        public static PersonalTourData Current
        {
            get
            {
                if (current == null)
                    current = new PersonalTourData();
                return current;
            }
        }
        #endregion

        #region Tour Group
        private TourGroup _previousGroup;
        public TourGroup PreviousGroup
        {
            get
            {
                if (_previousGroup == null)
                    _previousGroup = new TourGroup(Constants.PreviousTourId, Constants.PreviousTourTitle);
                return this._previousGroup;
            }
        }

        private TourGroup _joinGroup;
        public TourGroup JoinGroup
        {
            get
            {
                if (_joinGroup == null)
                    _joinGroup = new TourGroup(Constants.JoinTourId, Constants.JoinTourTitle);
                return this._joinGroup;
            }
        }

        private TourGroup _favouriteGroup;
        public TourGroup FavouriteGroup
        {
            get
            {
                if (_favouriteGroup == null)
                    _favouriteGroup = new TourGroup(Constants.FavouriteTourId, Constants.FavouriteTourTitle);
                return this._favouriteGroup;
            }
        }
        #endregion

        #region Tour Group Collection
        private ObservableCollection<TourGroup> _personalGroups;
        public ObservableCollection<TourGroup> PersonalGroups
        {
            get
            {
                _personalGroups = new ObservableCollection<TourGroup>();
                _personalGroups.Add(FavouriteGroup);
                _personalGroups.Add(PreviousGroup);
                _personalGroups.Add(JoinGroup);
                return this._personalGroups;
            }
        }
        #endregion

        #region Current Tour
        private CurrentTour _currentTour;
        public CurrentTour CurrentTour
        {
            get { return this._currentTour; }
            set { this._currentTour = value; }
        }
        #endregion

        #region Static Methods
        public static TourGroup GetItem(int uniqueId)
        {
            var matches = PersonalTourData.Current.PersonalGroups.Where(item => (item as TourGroup).Id.Equals(uniqueId));
            if (matches.Count() == 1) return matches.First();
            return default(TourGroup);
        }
        #endregion
    }
}